package com.common.android.utils.download;

import org.json.JSONException;
import org.json.JSONObject;


public class DownLoadData {
	public static final int SUCCESS=0;
	public static final int FAIL=1;
	public static final int DOWNLOADING=2;
	public static final int STOP=3;
	public static final int TO_START=4;
	
	private String mUrl="";						//下载的URL地址
	private String mFileName="";				//本地文件名（完整路径）
	private long mSize=0;						//文件大小
	private String mLastModify="";				//最近更新时间
	private int mState=4;						//下载状态
	private boolean mIsChaterDownload=false;	//是否允许断点续传
	private String mServerFileName="";			//服务端文件名
	private String mErrorMsg="";				//错误的信息
	public void setUrl(String url){
		mUrl=url;
	}
	
	public void setFileName(String name){
		mFileName=name;
	}
	
	public void setSize(long size){
		mSize=size;
	}
	
	public void setLastModify(String time){
		mLastModify=time;
	}
	
	public void setState(int state){
		mState=state;
	}
	
	public void setIsChaterDownload(boolean chater){
		mIsChaterDownload=chater;
	}
	
	public void setServerFileName(String anme){
		mServerFileName=anme;
	}
	
	public void setErrorMsg(String error){
		mErrorMsg=error;
	}
	
	public String getUrl(){
		return mUrl;
	}
	
	public String getFileName(){
		return mFileName;
	}
	
	public long getSize(){
		return mSize;
	}
	
	public String getLastModify(){
		return mLastModify;
	}
	
	public int getState(){
		return mState;
	}
	
	public boolean isChaterDownload(){
		return mIsChaterDownload;
	}
	
	public String getServerFileName(){
		return mServerFileName;
	}
	
	public String getErrorMsg(){
		return mErrorMsg;
	}
	
	public String toJSONString(){
		JSONObject object=new JSONObject();
		try {
			object.put("mUrl",mUrl );
			object.put("mSize",mSize);
			object.put("mLastModify",mLastModify );
			object.put("mFileName",mFileName);
			object.put("mState",mState);
			object.put("mErrorMsg",mErrorMsg);
		} catch (JSONException e) {
			e.printStackTrace();
			return null;
		}
		return object.toString();
	}
	
	public boolean parseFromJSONString(String jsonString){
		try {
			JSONObject object=new JSONObject(jsonString);
			mUrl=object.getString("mUrl");
			mSize=object.getLong("mSize");
			mLastModify=object.getString("mLastModify");
			mFileName=object.getString("mFileName");
			mState=object.getInt("mState");
			mErrorMsg=object.getString("mErrorMsg");
		} catch (JSONException e) {
			e.printStackTrace();
			return false;
		}
		return true;
	}
}
